package observer.plan_1;

/**
 * @author chenyuan
 * @date 2020/10/30 9:28
 */

/**
 * 包含最新的天气信息
 * 包含 CurrentConditions 对象
 * 当数据有更新时，主动的调用 CurrentConditions.update 方法，这样就可以显示最新的天气情况
 */
public class WeatherData {
    private float temperatrue;
    private float pressure;
    private float humidity;
    private CurrentConditions currentConditions;

    public WeatherData(CurrentConditions currentConditions) {
        this.currentConditions = currentConditions;
    }

    public float getTemperature() {
        return temperatrue;
    }

    public float getPressure() {
        return pressure;
    }

    public float getHumidity() {
        return humidity;
    }

    public void dataChange() {
        currentConditions.update(getTemperature(), getPressure(), getHumidity());
    }

    // 当数据有更新时，就调用该方法
    public void setData(float temperature, float pressure, float humidity) {
        this.temperatrue = temperature;
        this.pressure = pressure;
        this.humidity = humidity;
        // 将最新的信息推送给 CurrentConditions
        dataChange();
    }
}
